<!--  -->
<template>
    <div>
        <Card>
            <p slot="title">
                {{customer}}
            </p>
            <a  slot="extra" @click.prevent="goOut">
                <Icon type="backspace-outline"></Icon>
                退出配置
            </a>
            <Tabs type="card" v-model="tabs" @on-click="handleClickTabs">
                <TabPane name="app" label="APP首页">
                    <Card >
                        <p slot="title"><Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>首页设置</p>
                        <Button @click="handleAddGroup" slot="extra" size="small" class="zh-hollow" type="primary" icon="plus-round">新增分组</Button>
                        <Row type="flex" :gutter="10" align="middle">
                            <template v-if="group.length>0">
                                <Col v-for="(item,index) in group" :key="item.value"  :span="8">
                                    <Card>
                                        <p slot="title" >
                                            <Icon type="ios-box-outline"></Icon>
                                            {{item.group_name}}
                                        </p>
                                        <Button @click="handleEdit(item,index)"  slot="extra" size="small"  type="text" >编辑</Button>
                                        <Button @click="handleModule(item)" slot="extra" size="small"  type="text" >模块</Button>
                                        <Button @click="handleRemove(item)" style="color:#ed3f14" slot="extra" size="small"  type="text" >删除</Button>
                                        <template v-if="item.children.length>0">
                                            <p v-for="(child,index) in item.children" :key="index">{{child.group_name}}</p>
                                        </template>
                                        <p v-else>该分组下暂无模块</p>
                                    </Card>
                                </Col>
                            </template>
                            <Col v-else :span="24"><p>暂无分组</p></Col>
                        </Row>
                    </Card>
                    <Card style="marginTop:10px;">
                        <p slot="title"><Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>Banner设置</p>
                        <i-switch slot="extra" @on-change="changeSwitch"  v-model="banner_switch" ></i-switch> 
                        <Form :model="banner">
                            <FormItem>
                                <Select v-model="banner.banner1" :disabled="!banner_switch">
                                    <Option  v-for="item in bannerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                            <FormItem>
                                <Select v-model="banner.banner2" :disabled="!banner_switch">
                                    <Option  v-for="item in bannerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                            <FormItem>
                                <Select v-model="banner.banner3" :disabled="!banner_switch">
                                    <Option  v-for="item in bannerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                            <FormItem>
                                <Select v-model="banner.banner4" :disabled="!banner_switch">
                                    <Option  v-for="item in bannerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                            <FormItem>
                                 <Select v-model="banner.banner5" :disabled="!banner_switch">
                                    <Option  v-for="item in bannerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                        </Form>
                        <div style="textAlign:right">
                            <Button v-if="banner_switch" @click="saveBanner" class="zh-hollow" type="primary" >保存</Button>
                        </div>
                    </Card>
                </TabPane>
                <TabPane name="fuwushang" label="服务商">
                    <Card>
                        <p slot="title">
                            <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                            服务商
                        </p>
                        <Button v-if="!fac_edit"  slot="extra" size="small" class="zh-hollow" type="primary" @click="handleAddFac" >新增服务商</Button>
                        <Button 
                            v-if="facilitatorList.length>0||fac_edit"  
                            slot="extra" 
                            size="small" 
                            class="zh-hollow" 
                            type="warning"
                            style="marginLeft:15px;"
                            @click="fac_edit=!fac_edit" 
                        >
                            {{fac_edit?'完成':'编辑'}}
                        </Button>
                        <template v-if="facilitatorList.length>0">
                            <div class="zh-flex ">
                                <dl v-for="item in facilitatorList" :key="item.value" class="module-item">
                                    <dt class="module-item-body">
                                        <img :src="item.image_url" alt="">
                                        <Icon @click.native="removeFac(item)" :size="25" v-if="fac_edit" class="remove" type="minus-circled"></Icon>
                                    </dt>
                                    <dd class="module-item-foot">{{item.name}}</dd>
                                </dl>
                            </div>
                        </template>
                        <p v-else>暂无服务商</p>
                    </Card>
                    <Card style="marginTop:10px;">
                        <p slot="title">
                            <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                            供应商
                        </p>
                        <Button  v-if="!sup_edit" slot="extra" size="small" class="zh-hollow" type="primary" @click="handleAddSup" >新增供应商</Button>
                        <Button 
                            v-if="supplierList.length>0||sup_edit"  
                            slot="extra" 
                            size="small" 
                            class="zh-hollow" 
                            type="warning"
                            @click="sup_edit=!sup_edit"
                            style="marginLeft:15px;"  
                        >
                            {{sup_edit?'完成':'编辑'}}
                        </Button>
                        <template v-if="supplierList.length>0">
                            <div class="zh-flex ">
                                <dl v-for="item in supplierList" :key="item.value" class="module-item">
                                    <dt class="module-item-body">
                                        <img :src="item.image_url" alt="">
                                        <Icon @click.native="removeSup(item)" :size="25" v-if="sup_edit" class="remove" type="minus-circled"></Icon>
                                    </dt>
                                    <dd class="module-item-foot">{{item.name}}</dd>
                                </dl>
                            </div>
                        </template>
                        <p v-else>暂无供应商</p>
                    </Card>
                </TabPane>
                <TabPane name="wexiupeizhi" label="维修配置">
                    <Card>
                        <p slot="title">
                            <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                            维修配置
                            <Poptip placement="right-start" trigger="hover"  content="配置“设备维修”流程中的环节和参数。">
                                <Icon  style="color:#2d8cf0;cursor:pointer" type="information-circled"></Icon>
                            </Poptip>
                        </p>
                        <Row type="flex" align="middle" :gutter="10">
                            <Col :span="12">
                                <p>接单时是否须要反馈预计处理时间</p>
                                <RadioGroup v-model="configForm.receiptforecast">
                                    <Radio label="1" ><span>是</span></Radio>
                                    <Radio label="0" ><span>否</span></Radio>
                                </RadioGroup>
                            </Col>
                            <Col :span="12">
                                允许现场处理距离<InputNumber style="margin:0 5px 0 10px;" :max="2000" :min="500" number v-model="configForm.process_distance"></InputNumber>米
                            </Col>
                        </Row>
                        <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                            <Col :span="12">
                                分配时间限制<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" number v-model="configForm.time_max_distribute"></InputNumber>分钟
                            </Col>
                            <Col :span="12">
                                接单时间限制<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" number v-model="configForm.time_max_take_order"></InputNumber>分钟
                            </Col>
                        </Row>
                        <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                            <Col :span="12">
                                处理时间限制<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" number v-model="configForm.time_max_process"></InputNumber>天
                            </Col>
                            <Col :span="12">
                                任务完成<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" number v-model="configForm.time_max_score"></InputNumber>天后关闭评价入口（自动好评）
                            </Col>
                        </Row>
                        <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                            <Col :span="12">
                                <Button  @click="saveRepaireConfigInfo"  class="zh-hollow" type="primary" >保存</Button>
                            </Col>
                        </Row>
                    </Card>
                </TabPane>
                <TabPane name="xunjianpeizhi" label="巡检配置">
                    <Card>
                        <p slot="title">
                            <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                            巡检模板
                        </p>
                        <Button @click="getNoInspections"  slot="extra" size="small" class="zh-hollow" type="primary" >添加模板</Button>
                        <Table no-data-text="尚未添加巡检模板" :loading="temp_loading" :columns="xjtempColumns" :data="xjtempData" border></Table>
                        <Page :current.sync="temp_pageNumber"  :total="temp_total" show-total show-sizer @on-change="pageChange" @on-page-size-change="pageSizeChange"></Page>
                    </Card>
                </TabPane>
                <TabPane name="bangongyongpin" label="办公用品">
                    <Card>
                        <p slot="title">
                            <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                            办公用品配置
                            <Poptip placement="right-start" trigger="hover"  content="配置“办公用品采购”流程中的参数">
                                <Icon  style="color:#2d8cf0;cursor:pointer" type="information-circled"></Icon>
                            </Poptip>
                        </p>
                        <div>
                            <p>审批人数</p>
                            <Select v-model="ofPeoples" >
                                <Option  v-for="item in spList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                            </Select>
                        </div>
                        <div style="marginTop:10px;">
                            <p>确认收货时是否必须上传收货凭证</p>
                            <RadioGroup v-model="ofIsUploadCard">
                                <Radio label="1" ><span>是</span></Radio>
                                <Radio label="0" ><span>否</span></Radio>
                            </RadioGroup>
                        </div>
                        <div style="marginTop:10px;">
                            <Button @click='saveOffInfo'   class="zh-hollow" type="primary" >保存</Button>
                        </div>
                    </Card> 
                </TabPane>
                <TabPane name="pingzhengqingling" label="凭证请领">
                    <Card>
                        <p slot="title">
                            <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                            凭证请领配置
                            <Poptip placement="right-start" trigger="hover"  content="配置“凭证请领”流程中的参数">
                                <Icon  style="color:#2d8cf0;cursor:pointer" type="information-circled"></Icon>
                            </Poptip>
                        </p>
                        <div>
                            <p>审批人数</p>
                            <Select v-model="pzPeoples" >
                                <Option  v-for="item in spList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                            </Select>
                        </div>
                        <div style="marginTop:10px;">
                            <p>确认收货时是否必须上传收货凭证</p>
                            <RadioGroup v-model="pzIsUploadCard">
                                <Radio label="1" ><span>是</span></Radio>
                                <Radio label="0" ><span>否</span></Radio>
                            </RadioGroup>
                        </div>
                        <div style="marginTop:10px;">
                            <Button  @click="savePzInfo"  class="zh-hollow" type="primary" >保存</Button>
                        </div>
                    </Card> 
                </TabPane>
            </Tabs>
        </Card> 
        <!-- APP -->
        <Modal :loading="gloading" :title="modal_group_title" @on-ok="saveOneGroup" v-model="modal_group" :mask-closable="false" ok-text="保存" cancel-text="放弃操作">
            <Form :model="groupInfo" :label-width="60" style="padding:15px 30px;">
                <FormItem label="分组名称">
                    <Input v-model="groupInfo.groupName" :maxlength="20"></Input>
                </FormItem>
                <FormItem label="分组排序">
                    <InputNumber style="width:100%;"  :min="1" number v-model="groupInfo.seq"></InputNumber>  
                </FormItem>                
            </Form>
        </Modal>
        <Modal :loading='mloading' title="分组中的模块" v-model="modal_module" @on-ok="saveModuleInGroup" :mask-closable="false" ok-text="保存" cancel-text="放弃操作" >
            <div style="padding:15px 30px;">
                <Row style="margin:10px 0;" type="flex" align="middle" :gutter="10" v-if="moduleList.length>0" v-for="item in moduleList" :key="item.value">
                    <Col :span="9">
                        <Checkbox  v-model="item.selected" ><span>{{item.module_name}}</span></Checkbox>
                    </Col>
                    <Col :span="7">
                        <InputNumber placeholder="排序" :disabled="!item.selected" style="width:100%;"  :min="1"  v-model="item.seq" ></InputNumber>  
                    </Col>
                    <Col :span="8">
                        <Select :disabled="!item.selected" v-model="item.size" >
                            <Option   value="4">小图</Option>
                            <Option   value="8">大图</Option>
                        </Select>
                       
                    </Col>
                </Row>
            </div>
            
        </Modal>
        <!-- 服务商 -->
        <Modal width="630" :loading="serLoad" :title="addTitle" v-model="modal_add" :mask-closable="false" @on-ok="save" ok-text="保存" cancel-text="放弃操作">            
            <div class="zh-flex zh-flex-wrap " style="padding:15px">
                <template v-if="addedList.length>0">
                    <dl v-for="(item,index) in addedList" :key="item.value" class="module-item">
                        <dt class="module-item-body" style="cursor:pointer" @click="item.selected=!item.selected">
                            <img :src="domain+item.image_url" alt="">
                            <Icon  :size="25" v-if="item.selected" class="add" type="checkmark-circled"></Icon>
                        </dt>
                        <dd class="module-item-foot">{{item.name}}</dd>
                    </dl>
                </template>
                <p v-else>{{addType==='fac'?'暂无服务商':'暂无供应商'}}</p>
            </div>    
        </Modal>
        <!-- 巡检配置 -->
        <Modal :loading="addTemploading" title="添加模板" v-model="modal_add_temp" :mask-closable="false" @on-ok="addTemp" ok-text="保存" cancel-text="放弃操作">
            <div style="padding:15px 30px">
                <Table @on-selection-change="handleSelectChange" :columns="modalTempColumns" :data="modalTempData" border></Table>
                <Page :current.sync="temp_no_pageNumber" :page-size="temp_no_pageSize" :total="temp_no_total" show-total  @on-change="pageNoChange" ></Page>        
                <p>{{tip}}</p>
            </div>
        </Modal>
        <Modal :title="tempD.title" v-model="modal_temp" class="no_footer_modal">
            <Tabs type="card" v-model='tempTabName' >
                <TabPane v-for="(item,index) in tempD.tablabel" :key="index" :label="item.name" style="padding:15px 30px;">
                    
                        <div v-if="item.name!='意见与建议'" class="tempList-item" v-for="(child,num) in item.children" :key="num">
                            <p style="marginBottom:10px;">{{child.name}}</p>
                            <p  style="marginBottom:10px;" v-if="!!child.normal">{{child.normal}}</p>
                            <RadioGroup style="marginBottom:10px;"  type="button">
                                <Radio :label="child.good_text"></Radio>
                                <Radio :label="child.bad_text"></Radio>
                            </RadioGroup>
                            <Input readonly :placeholder="child.prompt"></Input>
                        </div>                       
                        <div v-else style="background:#eee">
                            <Card>
                                <div style="minHeight:250px;"></div>
                            </Card>
                        </div>
        
                </TabPane>
                
            </Tabs>
        </Modal>
    </div>

</template>

<script>
import {getTempDetails} from '@/libs/get.js'
import {
    getServiceList,
    deletePartnerService,
    getNoServiceList,
    addServiceForCus,
    getProviderList,
    deletePartnerProvider,
    getNoProviderList,
    addProviderForCus,
    getRepaireConfig,
    saveRepaireConfig,
    getParnterInspectionList,
    deleteTempInspection,
    getNoInspectionList,
    addTempSave,
    getModuleGroupInfo,
    deleteModuleGroup,
    addSaveGroup,
    getAllModules,
    saveModules,
    switchBanner,
    getBannerList,
    setBanner,
    getOffConfig,
    saveOffConfig,
    getPzConfig,
    savePzConfig
} from '@/libs/partner.js'
export default {
    name:'',
    data () {
        return {
            tempTabName:'',
            addTemploading:true,
            group_uuid:'',
            mloading:true,
            gloading:true,
            tip:'已选：0个',
            checked:[],
            temp_no_pageNumber:1,
            temp_no_pageSize:8,
            temp_no_total:0,
            temp_loading:true,
            temp_total:0,
            temp_pageNumber:1,
            temp_pageSize:10,
            serLoad:true,
            domain:this.$store.state.app.domain,
            customerUuid:this.$route.query.id,
            /**凭证请领 */
            pzPeoples:1,
            pzIsUploadCard:'1',
            /**办公用品 */
            ofPeoples:1,
            ofIsUploadCard:'1',
            spList:[
                {
                    label:'不需要审批',
                    value:0
                },
                {
                    label:'1人',
                    value:1
                },
                {
                    label:'2人',
                    value:2
                },
                {
                    label:'3人',
                    value:3
                }
            ],
            /**添加模板 */
            modal_temp:false,
            tempD:{},
            modalTempData:[],
            modalTempColumns:[
                {
                    type:'selection',
                    width:60,
                    align:'center',
                    title:'选择'
                },{
                    key:'name',
                    align:'center',
                    title:'模板名称'
                },{
                    key:'action',
                    title:'操作',
                    width:80,
                    render:(h,params)=>{
                        return h('Button',{
                                props:{
                                type:'text',
                                size:'small'
                                },
                                style:{
                                color:'#2D8CF0'
                                },
                                on:{
                                    click:()=>{
                                      this.viewTemp(params.row.uuid)
                                        
                                    }
                                }
                            },'查看')
                    }

                }
            ],
            modal_add_temp:false,
            xjtempColumns:[
                {
                    key:'name',
                    title:'模板名称',
                    align:'center'
                },
                {
                    key:'action',
                    title:'操作',
                    align:'center',
                    render:(h,params)=>{
                        return h('div',[
                            h('Button',{
                                props:{
                                type:'text',
                                size:'small'
                                },
                                style:{
                                color:'#2D8CF0'
                                },
                                on:{
                                    click:()=>{
                                        this.viewTemp(params.row.uuid)
                                        
                                    }
                                }
                            },'查看'),
                            h('Button',{
                                props:{
                                type:'text',
                                size:'small'
                                },
                                style:{
                                color:'#2D8CF0'
                                },
                                on:{
                                click:()=>{
                                    let config={
                                    title:'移除模板',
                                    content:'模板移除后，可重新从模板库中添加。移除模板不会影响已产生的巡检任务。',
                                    render:h=>{
                                        return h('div',{
                                            style:{
                                                padding:'30px 30px 0'
                                            }
                                        },[
                                            h('p','模板移除后，可重新从模板库中添加。'),
                                            h('p','移除模板不会影响已产生的巡检任务。')
                                        ])
                                    },
                                    okText:'移除',
                                    cancelText:'放弃操作',
                                    onOk:()=>{
                                        this.deleteTemp(params.row.kopuuid)
                                    }
                                    }
                                    this.$Modal.confirm(config)
                                }
                                }
                            },'移除'),
                        ])
                    }
                }
            ],
            xjtempData:[ ],
            /**维修配置 */
            configForm:{
                receiptforecast:1,
                process_distance:1000,
                time_max_distribute:3,
                time_max_take_order:3,
                time_max_process:5,
                time_max_score:5
            },
            /**服务商 */
            addedList:[],
            addTitle:'',
            addType:'',//fac,sup
            modal_add:false,
            facilitatorList:[],
            fac_edit:false,
            supplierList:[],
            sup_edit:false,
            /**APP首页 */
            modal_module:false,
            moduleList:[],
            bannerList:[],
            banner:{
                banner1:'',
                banner2:'',
                banner3:'',
                banner4:'',
                banner5:''
            },
            banner_switch:true,
            tabs:'app',
            customer:'',
            modal_group_title:'',
            modal_group:false,
            groupInfo:{
                uuid:'',
                groupName:'',
                seq:new Number()
            },
            group:[]
        };
    },
    methods:{
        handleClickTabs(name){
            switch(name){
                case 'app':this.getApp();this.getbanner();break;
                case 'fuwushang':this.getServices();this.getProviders();break;
                case 'wexiupeizhi':this.getRepaireConfigInfo();break;
                case 'xunjianpeizhi':this.getInspections();break;
                case 'bangongyongpin':this.getOffInfo();break;
                case 'pingzhengqingling':this.getPzInfo();break;
            }
        },
        //App设置
        async getApp(){
            let res= await getModuleGroupInfo(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.group=response.data;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async deleteGroup(uuid){
            let res= await deleteModuleGroup(uuid);
            let response=res.data;
            if(response.code==200){
                this.$Notice.success({
                    desc:"已删除"
                })
                this.getApp();
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        handleRemove(opt){
            let config={
                    title:'删除分组',
                    content:'删除分组，也将同时删除该分组下的模块，APP无法找到相应的模块入口。',
                    render:h=>{
                        return h('div',{style:{padding:'30px 30px 0'}},'删除分组，也将同时删除该分组下的模块，APP无法找到相应的模块入口。')
                    },
                    okText:'删除',
                    cancelText:'放弃操作',
                    onOk:()=>{
                        this.deleteGroup(opt.uuid)
                    }
                }
            this.$Modal.confirm(config)
        },
        async saveOneGroup(){
            if(this.groupInfo.groupName==''||this.groupInfo.groupName.length<=0){
                this.$Notice.error({
                    desc:'请输入分组名称'
                })
            }else if(!this.groupInfo.seq){
                this.$Notice.error({
                    desc:'请输入分组排序'
                })
            }else{
                let form =JSON.parse(JSON.stringify(this.groupInfo));
                form.partnerCode=this.customerUuid;
                let res= await addSaveGroup(form);
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:'已保存'
                    });
                    this.modal_group=false;
                    this.getApp();
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                }
            }
            let that=this;
            this.gloading=false;
            setTimeout(()=>{
                that.gloading=true;
            },500)
        },
        handleAddGroup(){
            this.modal_group_title="新增分组";
            this.modal_group=true;
        },
        handleEdit(opt,index){
            this.modal_group_title="编辑分组信息";
            this.modal_group=true;
            this.groupInfo={
                uuid:opt.uuid,
                groupName:opt.group_name,
                seq:Number.parseInt(opt.seq)
            }
        },
        async handleModule(opt){
            let res= await getAllModules(this.customerUuid,opt.uuid);
            let response=res.data;
            if(response.code==200){
                if(!response.data){
                    this.$Notice.warning({
                        desc:'请前往该客户的模块管理添加模块'
                    })
                }else{
                    this.moduleList=response.data.map(item=>{
                    if(!!item.size){
                        item.selected=true
                    }else{
                        item.selected=false
                    }
                    return item
                });
                this.group_uuid=opt.uuid;
                this.modal_module=true;
                }
                
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
            
        },
        async saveModuleInGroup(){
            let modules=this.moduleList.filter(item=>{
                if(item.selected){
                    return item
                }
            });
            if(modules.length>0){
                for(let i=0;i<modules.length;i++){
                    let item=modules[i];
                    if(!item.seq){
                        this.$Notice.error({
                            desc:`请输入${item.module_name}模块的排序`
                        });
                        return 
                    }else if(!item.size){
                        this.$Notice.error({
                            desc:`请输入${item.module_name}模块的图片类型`
                        });
                        return 
                    }
                }
                let module_uuid=modules.map(item=>{
                    return item.module_uuid
                }).join(',');
                let seq=modules.map(item=>{
                    return item.seq
                }).join(',');
                let sizes=modules.map(item=>{
                    return item.size
                }).join(',');
                let res= await saveModules({groupUUID:this.group_uuid,module_uuid,seq,sizes});
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:'已保存'
                    });
                    this.getApp();
                    this.modal_module=false;
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                }
            }else{
                this.modal_module=false;
            }
            
            let that=this;
            that.mloading=false;
            setTimeout(()=>{
                that.mloading=true;
            },500)
        },
        async changeSwitch(val){
            let b;
            if(val){
                b=1
            }else{
                b=0
            }
            let res= await switchBanner(this.customerUuid,b);
            let response=res.data;
            if(response.code==200){
                
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async getbanner(){
            let res= await getBannerList(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                let keys=Object.keys(response.data.banners);
                console.log(response.data.bannerState)
                this.banner_switch=!!parseInt(response.data.bannerState);
                console.log(this.banner_switch)
                let banners=response.data.banner;
                let len=banners.length;
                // for(let i=len;len<5;i++){
                //     banners[i]='';
                // }
                this.banner={
                    banner1:!!banners[0]?banners[0]:'',
                    banner2:!!banners[1]?banners[1]:'',
                    banner3:!!banners[2]?banners[2]:'',
                    banner4:!!banners[3]?banners[3]:'',
                    banner5:!!banners[4]?banners[4]:'',
                };
                console.log(this.banner)
                this.bannerList=keys.map((item,index)=>{
                    return {
                        name:response.data.banners[item],
                        uuid:item
                    }
                });
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        vs1(arr){
            for(let i=0;i<arr.length;i++){
                if(typeof(arr[i])=='string'&&arr[i].length>0){
                   return true 
                }
            }
            return false
        },
        vs2(arr){
            let na=arr.filter(item=>{
                if(typeof(item)=='string'&&item.length>0){
                   return item 
                }
            });
            let naa=[];
            for(let i=0;i<na.length;i++){
                if(!naa.includes(na[i])){
                    naa.push(na[i])
                }
            }
            if(naa.length==na.length){
                return true
            }else{
                return false
            }
        },
        async saveBanner(){
            let banner=Object.values(this.banner);
            if(!this.vs1(banner)){
                this.$Notice.error({
                    desc:'请选择banner'
                })
            }else if(!this.vs2(banner)){
                this.$Notice.error({
                    desc:'不能重复选择'
                })
            }else{
                let bannerList=banner.filter(item=>{
                    if(!!item){
                        return item
                    }
                });
            
                let banners=bannerList.join(',');
                let res= await setBanner(this.customerUuid,banners);
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:'已保存'
                    });
                    this.getbanner();
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                }
            }
            
        },
        
        
        //服务商TAB
        save(){
            if(this.addType==='fac'){
                this.addService();
            }else{
                this.addProvider();
            }
        },
        handleAddFac(){
            this.addType='fac';
            this.getNoServices();
        },
        handleAddSup(){
            this.addType='sup';
            this.getNoProviders();
        },
        async getServices(){
            let res= await getServiceList(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.facilitatorList=response.data.data;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async getNoServices(){
            let res= await getNoServiceList(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.addedList=response.data.partnerServiceList.map(item=>{
                    item.selected=false;
                    return item
                });
                this.modal_add=true;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async addService(){
            let provider_uuid=this.addedList.filter(item=>{
                if(item.selected){
                    return item
                }
            }).map(item=>{
                return item.provider_uuid
            }).join(',');
            if(provider_uuid.length<=0){
                this.modal_add=false;
            }else{
                let res= await addServiceForCus({partnerCode:this.customerUuid,provider_uuid});
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:'已保存'
                    });
                    this.getServices();
                    this.modal_add=false;
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                } 
                let that=this;
                this.serLoad=false;
                setTimeout(()=>{
                    that.serLoad=true;
                },500)
            }
        },
        async deleteService(uuid){
            let res= await deletePartnerService(uuid);
            let response=res.data;
            if(response.code==200){
                this.$Notice.success({
                    desc:"已移除"
                })
                this.getServices();
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        /**移除服务商 */
        removeFac(opt){
            let config={
                    title:'移除服务商',
                    content:'移除服务商不会删除该服务商下的历史数据，但该客户新的运维任务将无法分配给该服务商下的人员。',
                    okText:'移除',
                    cancelText:'放弃操作',
                    render:h=>{
                        return h('div',{
                            style:{
                                padding:'30px 30px 0'
                            }
                        },'移除服务商不会删除该服务商下的历史数据，但该客户新的运维任务将无法分配给该服务商下的人员。')
                    },
                    onOk:()=>{
                        this.deleteService(opt.uuid)
                    }
                }
            this.$Modal.confirm(config)
        },
        //供应商
        async getProviders(){
            let res= await getProviderList(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.supplierList=response.data.data;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async getNoProviders(){
            let res= await getNoProviderList(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.addedList=response.data.partnerSupplierList.map(item=>{
                    item.selected=false;
                    return item
                });
                this.modal_add=true;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async addProvider(){
            let supplier_uuid=this.addedList.filter(item=>{
                if(item.selected){
                    return item
                }
            }).map(item=>{
                return item.provider_uuid
            }).join(',');
            if(supplier_uuid.length<=0){
                this.modal_add=false;
            }else{
                let res= await addProviderForCus({partnerCode:this.customerUuid,supplier_uuid});
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:'已保存'
                    });
                    this.getProviders();
                    this.modal_add=false;
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                } 
                let that=this;
                this.serLoad=false;
                setTimeout(()=>{
                    that.serLoad=true;
                },500)
            }
        },
        async deleteProvider(uuid){
            
            let res= await deletePartnerProvider(uuid);
            let response=res.data;
            if(response.code==200){
                this.$Notice.success({
                    desc:"已移除"
                })
                this.getProviders();
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        /**移除供应商 */
        removeSup(opt){
            let config={
                    title:'移除供应商',
                    content:'移除供应商不会删除历史数据，但该客户将无法继续采购该供应商提供的物品。',
                    okText:'移除',
                    cancelText:'放弃操作',
                    render:h=>{
                        return h('div',{
                            style:{
                                padding:'30px 30px 0'
                            }
                        },'移除供应商不会删除历史数据，但该客户将无法继续采购该供应商提供的物品。')
                    },
                    onOk:()=>{
                        this.deleteProvider(opt.uuid)
                    }
                }
            this.$Modal.confirm(config)
        },

        //维修配置TAB
        async getRepaireConfigInfo(){
            
            let res= await getRepaireConfig(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                let data=response.data;
                this.configForm={
                    receiptforecast:data.receiptforecast!=null?data.receiptforecast:1,
                    process_distance:!!data.process_distance?data.process_distance:1000,
                    time_max_distribute:!!data.time_max_distribute?data.time_max_distribute:3,
                    time_max_take_order:!!data.time_max_take_order?data.time_max_take_order:3,
                    time_max_process:!!data.time_max_process?data.time_max_process:5,
                    time_max_score:!!data.time_max_score?data.time_max_score:5
                }
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async saveRepaireConfigInfo(){
            if(!this.configForm.process_distance){
                this.$Notice.error({
                    desc:'请输入允许现场处理距离'
                })
            }else if( !Number.isInteger(this.configForm.process_distance)){
                this.$Notice.error({
                    desc:'只能输入500~2000范围内的整数'
                })
            }else if(!this.configForm.time_max_distribute){
                this.$Notice.error({
                    desc:'请输入分配时间限制'
                })
            }else if(!Number.isInteger(this.configForm.time_max_distribute)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else if(!this.configForm.time_max_take_order){
                this.$Notice.error({
                    desc:'请输入接单时间限制'
                })
            }else if(!Number.isInteger(this.configForm.time_max_take_order)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else if(!this.configForm.time_max_process){
                this.$Notice.error({
                    desc:'请输入处理时间限制'
                })
            }else if(!Number.isInteger(this.configForm.time_max_process)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else if(!this.configForm.time_max_score){
                this.$Notice.error({
                    desc:'请输入自动好评的时间'
                })
            }else if(!Number.isInteger(this.configForm.time_max_score)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else{
                let form =JSON.parse(JSON.stringify(this.configForm));
                form.partnerCode=this.customerUuid;
                let res= await saveRepaireConfig(form);
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:"已保存"
                    })
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                }
            }
            
        },

        //巡检配置
        async getInspections(){
            this.temp_loading=true;
            let res= await getParnterInspectionList(this.customerUuid,this.temp_pageNumber,this.temp_pageSize);
            let response=res.data;
            if(response.code==200){
                this.temp_total=response.data.total;
                this.xjtempData=response.data.rows;
                this.temp_loading=false;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }  
        },
        pageChange(number){
            this.temp_pageNumber=number;
            this.getInspections();
        },
        pageSizeChange(size){
            this.temp_pageNumber=1;
            this.temp_pageSize=size;
            this.getInspections();
        },
        async getNoInspections(){
            let res= await getNoInspectionList(this.customerUuid,this.temp_no_pageNumber,this.temp_no_pageSize);
            let response=res.data;
            if(response.code==200){
                this.temp_no_total=response.data.total;
                this.modalTempData=response.data.rows;
                this.modal_add_temp=true;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }  
        },
        pageNoChange(number){
            this.temp_no_pageNumber=number;
            this.getNoInspections();
        },
        async addTemp(){
            if(this.checked.length<=0){
                this.$Notice.error({
                    desc:'未选择模板'
                })
            }else{
                let inspection_name=this.checked.map(item=>{
                    return item.uuid
                }).join(',');
                let res= await addTempSave(this.customerUuid,inspection_name);
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:'已保存'
                    });
                    this.temp_pageNumber=1;
                    this.getInspections();
                    this.modal_add_temp=false;
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                }
            }
            let that=this;
                this.addTemploading=false;
                setTimeout(()=>{
                    that.addTemploading=true;
                },500)
            
        },
        async deleteTemp(uuid){
            let res= await deleteTempInspection(uuid);
            let response=res.data;
            if(response.code==200){
                this.$Notice.success({
                    desc:'已删除'
                });
                this.temp_pageNumber=1;
                this.getInspections();
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        handleSelectChange(selection){
            let otherSelection=selection.filter(item=>{
                if(!this.checked.map(item=>{return item.uuid}).includes(item.uuid)){
                    return item
                }
            });
            this.checked=[...this.checked,...otherSelection];
            let checkeduuid=selection.map(item=>{
                return item.uuid
            });
            let nochecked=this.modalTempData.filter(item=>{
                if(!checkeduuid.includes(item.uuid)){
                    return item
                }
            });
            let nocheckeduuids=nochecked.map(item=>{
                return item.uuid
            })
            this.checked=this.checked.filter(item=>{
                if(!nocheckeduuids.includes(item.uuid)){
                    return item
                }
            })
            if(this.checked.length==0){
                this.tip="已选：0个"
            }else if(this.checked.length>2){
                this.tip=`已选：${this.checked[0].name}、${this.checked[1].name}等${this.checked.length}个模板`
            }else{
                this.tip=`已选${this.checked.length}个模板：`+this.checked.map(item=>{
                    return item.name
                }).join('，')
            }
        },
        async viewTemp(uuid){
            let res=await getTempDetails(uuid);
            let response=res.data;
            if(response.code===200){
                this.modal_temp=true;
                this.tempD=response.data;
                this.tempD.tablabel.push({name:'意见与建议'})
                this.tempTabName=this.tempD.tablabel[0].name;
            }else{
                this.$Notice.error({
                desc:response.msg
                });
            }
        },
        //办公用品
        async getOffInfo(){
            let res= await getOffConfig(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.ofIsUploadCard=response.data[0].officeforecast;
                this.ofPeoples=response.data[0].approver_num;
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            } 
        },
        async saveOffInfo(){
            let res= await saveOffConfig(this.customerUuid,this.ofPeoples,this.ofIsUploadCard);
            let response=res.data;
            if(response.code==200){
                this.$Notice.success({
                    desc:'已保存'
                })
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        //凭证
        async getPzInfo(){
            let res= await getPzConfig(this.customerUuid);
            let response=res.data;
            if(response.code==200){
                this.pzIsUploadCard=response.data[0].credentialforecast;
                this.pzPeoples=response.data[0].voucher_approver_num;
                console.log(this.pzPeoples)
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            } 
        },
        async savePzInfo(){
            let res= await savePzConfig(this.customerUuid,this.pzPeoples,this.pzIsUploadCard);
            let response=res.data;
            if(response.code==200){
                this.$Notice.success({
                    desc:'已保存'
                })
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        
        
        
        
        goOut(){
            this.$router.replace('/partner/cusmg')
        }
    },
    watch:{
        modal_group:function(){
            if(!this.modal_group){
                this.groupInfo={
                    uuid:'',
                    groupName:'',
                    seq:new Number()
                }
            }
        },
        addType:function(){
            this.addTitle=this.addType==='fac'?'新增服务商':'新增供应商';
        },
        facilitatorList:function(){
            if(this.facilitatorList.length<=0){
                this.sup_edit=false;
            }
        },
        modal_add_temp:function(){
            if(!this.modal_add_temp){
                this.tip='已选：0个';
                this.checked=[];
                this.temp_no_pageNumber=1;
            }
        }
    },
    created(){
        this.customer=localStorage.configName;
        this.handleClickTabs(this.tabs);
    }

}

</script>
<style lang='scss' >
.ivu-tabs-tabpane{
    padding-left:5px;
}
.rotate-title-icon {
    transform: rotate(90deg);
    font-size: 20px;
}
.module-item{
    text-align:center;
    margin:5px 15px;
    width:120px;
    &-body{
        width:120px;
        height:120px;
        position:relative;
        img{    
            width:120px;
            height:120px;
            display:block;
        }
        .remove{
            position:absolute;
            width:25px;
            height:25px;
            top:0;
            right:0;
            color:#ed3f14;
            z-index:100;
            cursor: pointer;
        }
        .add{
            position:absolute;
            width:25px;
            height:25px;
            top:0;
            right:0;
            color:#19be6b;
            z-index:100;
            cursor: pointer;
        }
    }
    &-foot{
        margin-top:10px;
        display: block;
    }
}
</style>